#include "Compare_Result.h"
#include "_LDIF.h"


Compare_Result::Compare_Result(char *ras,bool s,vector<Atribut<char*>> atrib_comp):LDAP_Result(ras,s),atribut_de_comparat(atrib_comp)
{
	
	ldif_Result = 0;

}




Compare_Result::~Compare_Result(void)
{
}


void Compare_Result::ldif_CompareResult()
{

	vector<Atribut<char*>> exits;
	Atribut<char *> a;

	for(int i=0;i<atribut_de_comparat.size();i++)
	{
		if(strstr(raspuns,atribut_de_comparat[i].daNume()))
		{
			a.setAtribut(atribut_de_comparat[i].daNume(),atribut_de_comparat[i].daAtribut());
			exits.push_back(a);
		}
	}

	_LDIF ldif_modify(exits);
	char ldif[100];
	strcpy(ldif,ldif_modify.Da_LDIF());

	this->ldif_Result = new char[strlen(ldif)+1];
	strcpy(ldif_Result,ldif);

}


void Compare_Result::afisareResult()
{
	ldif_CompareResult();

	if(Succes==false)
		throw new Compare_Result_Exception("",1);


	cout<<"\n->Rezultatele operatiei compare sunt:: \n";
	FILE *f = fopen(ldif_Result,"r");
	if(!f)
	{
		system("Eroare");
		exit(1);
	}

	char result[100];

	while(fgets(result,100,f))
	{
		printf("\n%s",result);
	}

	cout<<"\nAceste rezultate s-au salvat in fisierul "<<ldif_Result;

}



